/*
 * Copyright (C) 2012 Jesse Webb (gweebz@gmail.com)
 *
 * This file is part of Gwahtzee.
 *
 * Gwahtzee is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gwahtzee is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gwahtzee.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.googlecode.gwahtzee.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.ArrayList;

public class Dice extends ArrayList<Die> {
    private static final int SIZE = 5;

    public Dice() {
        super(SIZE);
        for (int i = 0; i < SIZE; i++) {
            add(new Die());
        }
    }

    public int roll() {
        int total = 0;
        for (Die die : this) {
            total += die.roll();
        }
        return total;
    }

    public int getTotal() {
        int total = 0;
        for (Die die : this) {
            total += die.getFaceValue();
        }
        return total;
    }

    @Override
    public String toString() {
        ToStringBuilder toStringBuilder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
        for (int i = 0; i < size(); i++) {
            String label = String.format("[%d]", i);
            toStringBuilder.append(label, get(i));
        }
        return toStringBuilder.toString();
    }
}
